home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6738 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  61 lines

  1. Path: sun001.spd.dsccc.com!spd!jmccarty
  2. From: jmccarty@spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: sscanf bug??????
  5. Date: 14 Feb 1996 19:38:34 GMT
  6. Organization: DSC Communications Corporation, Plano, Texas USA
  7. Message-ID: <4ftdnq$b0c@sun001.spd.dsccc.com>
  8. References: <4fimvo$82s@fnord.dfw.net> <4frr9j$ie8@fnord.dfw.net>
  9. NNTP-Posting-Host: aplo139.spd.dsccc.com
  10.  
  11. In article <4frr9j$ie8@fnord.dfw.net>,
  12. Jerry Jackson <jtmcap@dfw.dfw.net> wrote:
  13. )Jerry Jackson (jtmcap@dfw.dfw.net) wrote:
  14. ): the following is a program compiled using microway ndp c/c++ compiler.
  15. ): 
  16. ): #include <stdio.h>
  17. ): #include <string.h>
  18. ): 
  19. ): main()
  20. ): {
  21. ):     char str_1[] = "013196";
  22. ):     char str_2[] = "13196";
  23. ):     long res_1, res_2;
  24. ): 
  25. ):     sscanf(str_1,"%d",&res_1);
  26. ):     sscanf(str_2,"%d",&res_2);
  27. ): 
  28. ):     printf("\nres_1 = %d",res_1);
  29. ):     printf("\nres_2 = %d",res_2);
  30. ): }
  31. ): 
  32. ): the output looks like this:
  33. ): 
  34. ): res_1 = 89
  35. ): res_2 = 13196
  36. ): 
  37. ): 
  38. ): microway says that the leading zero causes sscanf to do an octal 
  39. ): conversion on the integer.  i have not found any documentation to verify 
  40. ): this.  also other compilers that i use return the value 13196 for both 
  41. ): calls to sscanf.
  42. ): 
  43. ): bug or undocumented feature?
  44. ): 
  45.  
  46. Per the ANSI standard, "%d" specifies a decimal integer, whereas "%i"
  47. specifies integer, the string may begin with 0 (indicating octal
  48. translation), or either of "0x" or "0X" to specify hexadecimal
  49. translation. So if it is a "feature", it is not ANSI.
  50.  
  51. In any case, 013196 (octal) is 718 decimal. 718 decimal mod 256 is 206.
  52. I don't see anything reasonable it could be the mod of that would
  53. result in 89. So even if it is an "undocumented feature" or non-ANSI
  54. extension, I don't think it is working properly.
  55.  
  56. Mike
  57. ----
  58. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  59.  
  60. I don't speak for DSC.         <- They make me say that.
  61.